/*
 * clock.c
 *
 *  Created on: 2016-10-22
 *      Author: m
 */
#include "clock.h"
#include "global.h"
#include "string.h"
#include "sub.h"
#include "i8259.h"
#include "kernel.h"

void init_clock() {
    set_irq_handler(CLOCK_IRQ, clock_handler);
    enable_irq(CLOCK_IRQ);
}

void clock_handler(int irq) {
    ++g_ticks;
    if(g_proc_ready->ticks > 0) {
        g_proc_ready->ticks--;
    }

    if(0 != g_reenter) { //中断重入，则不进行调度
        //printf("!");
        return;
    }

    shedule();
}


